<?php
/**
 * Created by PhpStorm.
 * User: longyuanmoqi
 * Date: 2016/10/25
 * Time: 9:38
 */
header('Content-type:text/html;charset=utf-8');
$link=mysqli_connect('localhost','root','');
if(!$link) {
    die('连接数据库失败！'.mysqli_error($link));
}

mysqli_query($link,'set names utf8');
mysqli_query($link,'use `itcast`');

$page=isset($_GET['page']) ? $_GET['page'] : 1;
$page_size=2;
$lim=($page-1)*2;


$result =mysqli_query($link,'select count(*) from `emp_info`');
$count = mysqli_fetch_row($result);
$count=$count[0];

$max_page=ceil($count/$page_size);
$page=isset($_GET['page']) ? intval($_GET['page']):1;
$page=$page>$max_page ? $max_page:$page;
$page=$page<1 ? 1:$page;


$page_html="<a href='./showList.php?page=1'>首页</a> &nbsp;";
$page_html.="<a href='./showList.php?page=".(($page-1)>0?($page-1):1)."'>上一页</a>&nbsp;";
$page_html.="<a href='./showList.php?page=".(($page+1)<$max_page?($page+1):$max_page)."'>下一页</a>&nbsp;";
$page_html.="<a href='./showList.php?page={$max_page}'>尾页</a>";

$sql="select * from `emp_info` limit $lim,2";
$result=mysqli_query($link,$sql);

$emp_info=array();
while($row=mysqli_fetch_assoc($result)){
    $emp_info[]=$row;}
define('APP','itcast');
require 'list_html.php';